<?php

use yii\helpers\Html;
use yii\widgets\LinkPager;
use yii\grid\GridView;
use kartik\date\DatePicker;

/**
 * @var yii\web\View $this
 * @var amnah\yii2\user\Module $module
 * @var array $actions
 */
global $regionTypes2;
global $prodAttrCodes;
$regionTypes2 = $regionTypes;
$module = $this->context->module;

$this->title = Yii::t('user', 'Yii 2 User');

// 增加客源的按钮
$createUrl                           = [];
$createUrl[]                         = '/prod/cust/create';
$createUrl['attr_type_spec_id']   = '20001';
$createUrl['prod_spec_name']       = '客源';
$createUrl['last_url'] = $now_url;


?>
<style>
    .table thead>tr>th, .table thead>tr>td .form-control,.table tbody>tr>th, .table tfoot>tr>th, .table thead>tr>td, .table tbody>tr>td, .table tfoot>tr>td, .table thead>tr>td input{font-size:12px;line-height:24px;padding:3px;height:24px;}
</style>

    <section class="content-header">
        <h1>
            客源
            <small>全部客源</small>

        </h1>
        <ol class="breadcrumb">
            <?php
            // 创建客源按钮
            echo Html::a( Html::tag('span', Yii::t('region', 'Create') .'客源' , ['class' => "glyphicon fa fa-plus-square"])   . $region_name. Yii::t('region', $region_type_name) , $createUrl, ['class' => 'btn btn-block btn-success btn-sm']);
            ?>
        </ol>
    </section>

<?php if ($orderCounts): ?>
    <section class="content-header">
        <div class="row">
            <?php

            if($myid==1){
                echo   $this->render('index_head1',
                    [
                        'orderCounts'=>$orderCounts,
                        'now_url'=>$now_url,
                        'hisTotalOrder' =>  $hisTotalOrder,
                        'objectTypes' => $objectTypes,
                        'attr_type_spec_id' => 30001,
                        'prodSpecName' =>$prodSpecName,
                        'dataProvider' => $dataProvider,
                        'searchModel' =>  $searchModel,
                        'regionCnt' => $regionCnt,
                        'attrSpecs' => $attrSpecs,
                        'regionTodayCnt' => $regionTodayCnt,
                        'authority'=>$authority,
                        'model_mng'=>$model_mng,
                        ]);
            }elseif($myid==2){
                echo   $this->render('index_head',
                    [
                        'orderCounts'=>$orderCounts,
                        'now_url'=>$now_url,
                        'hisTotalOrder' =>  $hisTotalOrder,
                        'objectTypes' => $objectTypes,
                        'attr_type_spec_id' => 30001,
                        'prodSpecName' =>$prodSpecName,
                        'dataProvider' => $dataProvider,
                        'searchModel' =>  $searchModel,
                        'regionCnt' => $regionCnt,
                        'attrSpecs' => $attrSpecs,
                        'regionTodayCnt' => $regionTodayCnt,
                        'authority'=>$authority,
                        'model_mng'=>$model_mng,
                        ]);
            }



            ?>


        </div>
    </section>
<?php endif; ?>






    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title">客源清单表格</h3>
                        <div class="box-tools">
                            <div class="pull-right" style="width: 300px;">
                                <?php if($times): ?>
                                <input  type="text" name="phone" id="txt" placeholder="请输入电话号码"/>
                                <a href="#"  id="goto">
                                    <button class="btn btn-warning btn-flat btn-sm" id="go">电话查找</button>
                                </a>
                                <span style="color: red;"></span>
                                <?php  endif; ?>
                            </div>
                            <div class="input-group input-group-sm" style="width: 250px;">
                                <?php
                                if($times){


                                    $date=date("Y-m");
                                    $datetime = new \DateTime();
                                    $interval = \DateInterval::createFromDateString('last month');
                                    $period = new \DatePeriod($datetime, $interval, 6,DatePeriod::EXCLUDE_START_DATE);

                                    echo "<a  class='btn  btn-success btn-sm' href=/prod/order/myorder?object_id=1&time=".$date.">本月客源查询</a>";
                                    echo " &nbsp";
                                    foreach ($period as $date) {

                                    }
                                    echo "<a  class='btn  btn-success btn-sm' href=/prod/order/myorder?object_id=1&time=".$date->format('Y-m'), PHP_EOL.">近6个月客源查询</a>";

                                }

                                ?>
                            </div>
                            <div class="pull-right" style="width: 100px;">
                                <?php  $url=Yii::$app->request->getUrl();  $check =strpos($url, '&a=');  ?>
                                <?php if($check !== false): ?>
                                    <?php echo Html::a(Yii::t('region', 'Back'), Yii::$app->request->getReferrer(), ['class' => 'btn btn-default']); ?>
                                <?php  endif; ?>
                            </div>
                        </div>
                        <div class="nav-tabs-custom" style="margin: 10px 0px;">
                            <div style="float: left;margin-right: 10px;padding:2px;" id="area">
                                <span >区域多选</span>
                            </div>
                            <div style="float: left;display: none;">
                                <ul class="nav nav-tabs" >
                                    <?php
                                    foreach($model_d as $k=>$v){
                                        echo "<li style='padding: 0px 10px;'><input type='checkbox' name='checkbox' value='".$k."'>".$v."</li>";

                                    }
                                    ?>
                                </ul>
                            </div>

                        </div>
                    </div>
                    <div class="box-body">
                        <div class="row">

                        <?php
                    echo    $this->render('index_context',
                            [
                                'model_staff_name'=>$model_staff_name,
                                'authority'=>$authority,
                                'encrypted'=>$encrypted,
                                'custSourceType'=>$custSourceType,
                                'custSources'=>$custSources,
                                'now_url'=>$now_url,
                                'domainSources'=>$domainSources,
                                'customs'=>$customs,
                                'orderStates' => $orderStates,
                                'orderStatesd'=>$orderStatesd,
                                'regions' => $regions,
                                'domains' => $domains,
                                'black'=>$black,
                                'public_flag' => $public_flag,
                                'hisTotalOrder' =>  $hisTotalOrder,
                                'objectTypes' => $objectTypes,
                                'attr_type_spec_id' => 30001,
                                'prodSpecName' =>$prodSpecName,
                                'dataProvider' => $dataProvider,
                                'searchModel' =>  $searchModel,
                                'regionCnt' => $regionCnt,
                                'attrSpecs' => $attrSpecs,
                                'model_d' => $model_d,
                                'regionTodayCnt' => $regionTodayCnt,
                                'model_mng'=>$model_mng,]);

                        ?>

                        </div>
                    </div>
                </div>
            </div>
        </div>

    </section>


<?php

$js = <<<JS
jQuery('#go').on('click',function() {

    if(!(/^1[34578]\d{9}$/.test($("#txt").val()))){
        $(this).parent().next().html("请输入正确的手机号码");

    }else{
        $(this).parent().next().html("");
        $('#goto').attr('href',"/prod/order/myorder?object_id=1&phone="+$("#txt").val());
    }

});
JS;
$this->registerJs($js);


//复选框点多选
$js = <<<JS
jQuery('#area').on('click',function() {

    $(this).next().toggle();

});


JS;
$this->registerJs($js);
?>




